﻿using System;
using System.Windows.Input;
using Microsoft.Practices.Prism.Commands;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.Regions;
using Tanmia.Basis.Prism;
using Tanmia.Basis.ViewInterface;
using Tanmia.Basis.ViewModel;
using Tanmia.Warehouse.Core;
using Tanmia.Warehouse.Domain;

namespace Tanmia.Warehouse.Presentation.Scenarios
{
    [ViewInfo("استعراض المواد", Constants.RegionMain, Views.ItemBrowser)]
    public class ItemBrowserViewModel : BrowserViewModel<Item>
    {
        public ICommand ShowEditorCommand { get; private set; }

        public ItemBrowserViewModel(IShellView shellView, IRegionManager regionManager, IEventAggregator eventAggregator, IMessageService messageService, ItemDomain itemObj)
            : base(shellView, regionManager, eventAggregator, messageService, itemObj)
        {
            EntityName = "Item";

            ShowEditorCommand = new DelegateCommand(OnShowEditor, OnCanDelete);
        }

        protected virtual void OnShowEditor()
        {
            RegionManager.NavigateToEditor(Views.ItemEditor, CurrentEntity);
        }

        protected override void CurrentChangedHandler(object sender, EventArgs e)
        {
            base.CurrentChangedHandler(sender, e);
            ((DelegateCommand)ShowEditorCommand).RaiseCanExecuteChanged();
        }
    }
}
